package com.bjxst;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

/**为文件中内容添加行号*/
public class LineNumberDemo {
    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try{
            br = new BufferedReader(new FileReader("d:/b.txt"));
            bw = new BufferedWriter(new FileWriter("d:/cc.txt"));
            String temp ="";
            int i = 1;//序号
            while ((temp= br.readLine()) != null){
                bw.write(i+"，"+temp);
                bw.newLine();
                i++;
            }
            bw.flush();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(br != null){
                    br.close();
                }
                if(bw != null){
                    bw.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
